package com.qf.topics;

import com.qf.util.ConnUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.io.IOException;

public class Publisher {

    @Test
    public void publish() throws IOException {
        //1. 获取connection对象
        Connection connection = ConnUtil.getConnection();

        //2. 创建Channel对象
        Channel channel = connection.createChannel();

        //3. exchange-topics
        channel.exchangeDeclare("topic-exchange", BuiltinExchangeType.TOPIC);

        //4. queue
        channel.queueDeclare("topic-queue1",true,false,false,null);
        channel.queueDeclare("topic-queue2",true,false,false,null);

        //5. binding
        channel.queueBind("topic-queue1","topic-exchange","*.orange.*");

        channel.queueBind("topic-queue2","topic-exchange","*.*.rabbit");
        channel.queueBind("topic-queue2","topic-exchange","lazy.#");


        //6. send msg
        channel.basicPublish("topic-exchange","lazy.xxx.aaaa",null,"yyy".getBytes());

    }
}
